import pymysql
import json

def cleanup():
    # 连接数据库
    conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', 
                          password='123456', database='drcurd', charset='utf8')
    cursor = conn.cursor()
    
    # 读取测试用户名并删除
    with open('../data/register_data.json', 'r', encoding='utf-8') as f:
        usernames = [item['req_data']['username'] for item in json.load(f)]
    
    for username in usernames:
        cursor.execute("DELETE FROM tshop.user WHERE username = %s", (username,))
        print(f"删除: {username}" if cursor.rowcount > 0 else f"不存在: {username}")
    
    conn.commit()
    cursor.close()
    conn.close()
    print(f"清理完成，共处理 {len(usernames)} 个用户名")

if __name__ == "__main__":
    cleanup() 